﻿using System.ComponentModel;
using Catel.Articles._04___Unit_testing.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Catel.Articles._04___Unit_testing.Test.Models
{
    [TestClass]
    public class PersonTest
    {
        [TestMethod]
        public void Validation()
        {
            Person person = new Person();
            IDataErrorInfo personAsErrorInfo = (IDataErrorInfo) person;

            Assert.IsTrue(person.HasErrors);
            Assert.IsFalse(string.IsNullOrEmpty(personAsErrorInfo[person.GenderProperty.Name]));
            Assert.IsFalse(string.IsNullOrEmpty(personAsErrorInfo[person.FirstNameProperty.Name]));
            Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.MiddleNameProperty.Name]));
            Assert.IsFalse(string.IsNullOrEmpty(personAsErrorInfo[person.LastNameProperty.Name]));

            person.Gender = Gender.Male;
            person.FirstName = "John";
            person.LastName = "Doe";

            Assert.IsFalse(person.HasErrors);
            Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.GenderProperty.Name]));
            Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.FirstNameProperty.Name]));
            Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.MiddleNameProperty.Name]));
            Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.LastNameProperty.Name]));
        }

        [TestMethod]
        public void FullName()
        {
            Person person = new Person();
            Assert.IsTrue(string.IsNullOrEmpty(person.FullName));

            person.FirstName = "Geert";
            Assert.AreEqual("Geert", person.FullName);

            person.MiddleName = "van";
            Assert.AreEqual("Geert van", person.FullName);

            person.LastName = "Horrik";
            Assert.AreEqual("Geert van Horrik", person.FullName);

            person.MiddleName = string.Empty;
            Assert.AreEqual("Geert Horrik", person.FullName);
        }
    }
}
